﻿
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System;

using System.Data.SqlClient;
using System.Web.Services;

using System.Data;
using System.Configuration;
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.SqlClient;
using System.Drawing;
using System.Net.Mail;

using System.Web.Services;

using System.IO.MemoryMappedFiles;

public partial class admin_view : System.Web.UI.Page
{
    string ss;
    private byte[] ConvertImageToByteArray(System.Drawing.Image imageToConvert, System.Drawing.Imaging.ImageFormat formatOfImage)
    {
        byte[] Ret;
        try
        {
            using (MemoryStream ms = new MemoryStream())
            {
                imageToConvert.Save(ms, formatOfImage);
                Ret = ms.ToArray();
            }
        }
        catch (Exception) { throw; }
        return Ret;
    }
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["email"] == null)
        {
            Session["email"] = "admin";
        }
        ss = Session["p_id"].ToString();
        Label1.Text = Session["email"].ToString();
        
        if (Page.IsPostBack)
        {
        }
        else
        {
            string str = Session["p_id"].ToString();
           // Image1 .ImageUrl ="property.ashx?p_id=" + str.ToString();
            SqlConnection conn = null;
            conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnStr"].ConnectionString);


            conn.Open();
            SqlCommand scmd = new SqlCommand("SELECT * FROM property_rent where c_id='" + Session["p_id"] + "'", conn);

            SqlDataReader dr = scmd.ExecuteReader();
            if (dr.Read())
            {

                txtfname1.Text = dr[6].ToString();
                Label2.Text = dr[7].ToString();
                lblstreet.Text = dr[11].ToString();
                lblprice.Text = dr[40].ToString();
                lblproptype.Text=dr[4].ToString ();
                lblcond.Text = dr[55].ToString();
                lblelevatr.Text = dr[51].ToString();
                lblparking.Text = dr[63].ToString();
                Label3.Text = dr[41].ToString();
                lblac.Text = dr[35].ToString();
                Lblpermises.Text = dr[79].ToString();
                lblssn.Text = dr[8].ToString();
                lblcity.Text = dr[16].ToString();
              Lblda.Text = dr[81].ToString();
                lbltype.Text = "Want To Rent";
                Label4.Text = dr[2].ToString();
            }


            dr.Close();
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {




        if (e.CommandName == "view")
        {

            //Label1.Text = "hello";
            int index = Convert.ToSByte(e.CommandArgument);

            GridViewRow row = GridView1.Rows[index];
            SqlDataAdapter adp = new SqlDataAdapter();
            SqlCommand cmd1 = new SqlCommand();
            DataSet ds = new DataSet();


            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connstr"].ConnectionString);

            con.Open();

            SqlCommand objectvalue = new SqlCommand("", con);
            cmd1.Connection = con;



            SqlCommand dmc = new SqlCommand("select p_id from properties_rent where p_id='" + row.Cells[0].Text + "'", con);

            dmc.ExecuteNonQuery();
            Session["p_id"] = row.Cells[0].Text;

            con.Close();
            // Response.Write(Session["p_id"]);
            // Response.Write(@"<script language='javascript'>alert('clent has been selected')</script>");

            Response.Redirect("view_for_rent.aspx");
            // con.Close();


        }
    }


    protected void Save_Click(object sender, EventArgs e)
    {
        
    }
    protected void SearchButton_Click(object sender, EventArgs e)
    {
      

      //  string pageurl="Default.aspx?Id=6&RollNo=15";

      //Response.Write(<script> window.open( ‘"+pageurl+"’,'_blank' ); </script>);
      //Response.End();
    }
    
    protected void LinkButton1_Click(object sender, System.EventArgs e)
    {
        Session.Abandon();
        Response.Redirect("../admin.aspx");
    }
}